@echo off
set COMPILER=%WINDIR%\microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe
set OUT=%2
set IN=%1

if "%1" == "?" goto HELP
if NOT EXIST %COMPILER% goto ERRORCOMPILER

if "%OUT%" == "" set OUT=..\compiled
if "%IN%" == "" set IN=.\Qube
if "%OUT%" == "*" set OUT=..\compiled
if "%IN%" == "*" set IN=.\Qube

if NOT EXIST %IN% goto ERRORINPUT
if NOT EXIST %OUT% mkdir %OUT%

echo Compiling...
%COMPILER% -p %IN% -v "/" %OUT% -f > compile.log
if %ERRORLEVEL% NEQ 0 goto ERROR

echo Removing temporary files...
del %OUT%\*.log
del %OUT%\bin\*.pdb
del %OUT%\bin\*.xml
del %OUT%\*.csproj
del %OUT%\*.csproj.user
rmdir %OUT%\obj\ /s /q

echo Done!
del compile.log
goto END

:ERROR
echo Errors while compiling. See 'compile.log' for details!
goto END

:ERRORINPUT
echo.Input folder '%IN%' not found! 
goto END

:ERRORCOMPILER
echo Could not locate 'aspnet_compiler'. Make sure you have .NET framework installed. Compiler should be at '%COMPILER%'.
goto END

:HELP
echo Compile web site.
echo 	Usage: build.bat [input_dir] [output_dir]
echo 	If output_dir is not specified it's set to '..\compiled'.
echo 	If input_dir is not specified you don't know you're buisness.
goto END

:END